package online.longzipeng.modules.sys.controller;

import io.swagger.annotations.*;
import online.longzipeng.common.constant.Constant;
import online.longzipeng.common.page.PageData;
import online.longzipeng.common.page.PageParam;
import online.longzipeng.common.utils.Result;
import online.longzipeng.modules.sys.dto.SysUserDTO;
import online.longzipeng.modules.sys.dto.SysUserSearchDTO;
import online.longzipeng.modules.sys.pojo.param.SearchParam;
import online.longzipeng.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @Author: lzp
 * @description:
 * @Date: 2022/12/22
 */
@RestController
@RequestMapping("/test")
@Api(tags = "测试接口")
public class TestController {

	@Autowired
	private SysUserService sysUserService;

	@GetMapping("/hello")
	@ApiOperation("问候")
	public String hello(@ApiParam(value = "问候语", required = true) @RequestParam String word) {
		return "web_demo:" + word;
	}

	@PostMapping("/search")
	@ApiOperation("搜索")
	public String search(@RequestBody SearchParam searchParam) {
		return "web_demo:" + searchParam.getKeyword();
	}

	@GetMapping("/page/user1")
	@ApiOperation("用户分页【人人开源】")
	@ApiImplicitParams({
			@ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
			@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
			@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "gender", value = "性别", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataType = "String")
	})
	public Result<PageData<SysUserDTO>> pageUser1(@ApiIgnore @RequestParam Map<String, Object> params) {
		PageData<SysUserDTO> page = sysUserService.page(params);
		return new Result<PageData<SysUserDTO>>().ok(page);
	}

	@PostMapping("/page/user2")
	@ApiOperation("用户分页【自定义分页对象】")
	public Result<PageData<SysUserDTO>> pageUser2(@RequestBody SysUserSearchDTO param) {
		PageData<SysUserDTO> page = sysUserService.page(param);
		return new Result<PageData<SysUserDTO>>().ok(page);
	}

	@PostMapping("/page/user3")
	@ApiOperation("用户分页【泛型的写法】")
	public Result<PageData<SysUserDTO>> pageUser3(@RequestBody PageParam<SysUserSearchDTO> pageParam) {
		return new Result<PageData<SysUserDTO>>();
	}

}
